/* * generated by Xtext */ package it.xsemantics.example.fj.formatting; import it.xsemantics.example.fj.services.FJGrammarAccess.*; import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter; import org.eclipse.xtext.formatting.impl.FormattingConfig; /** * This class contains custom formatting description. * * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting * on how and when to use it * * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an * example */ public class FJFormatter extends AbstractDeclarativeFormatter { @Override protected void configureFormatting(FormattingConfig c) { it.xsemantics.example.fj.services.FJGrammarAccess f = (it.xsemantics.example.fj.services.FJGrammarAccess) getGrammarAccess(); c.setAutoLinewrap(80); c.setSpace(" "); // Fields // add line breaks after a field declaration FieldElements fieldAccess = f.getFieldAccess(); c.setLinewrap(1).after(fieldAccess.getSemicolonKeyword_2()); // remove possible spaces before the ; ending a field declaration c.setNoSpace().before(fieldAccess.getSemicolonKeyword_2()); // Methods MethodElements methodAccess = f.getMethodAccess(); c.setLinewrap(1).after(methodAccess.getRightCurlyBracketKeyword_7()); c.setNoSpace().around(methodAccess.getLeftParenthesisKeyword_2()); c.setNoSpace().before(methodAccess.getRightParenthesisKeyword_4()); c.setNoSpace().before(methodAccess.getCommaKeyword_3_1_0()); c.setNoSpace().around(f.getExpressionAccess().getFullStopKeyword_1_0_1()); c.setNoSpace().before(f.getMethodBodyAccess().getSemicolonKeyword_2()); // Method and constructor invocations NewElements newAccess = f.getNewAccess(); c.setNoSpace().before(newAccess.getCommaKeyword_3_1_0()); c.setNoSpace().around(newAccess.getLeftParenthesisKeyword_2()); c.setNoSpace().before(newAccess.getRightParenthesisKeyword_4()); // indentations for { } of classes ClassElements classAccess = f.getClassAccess(); c.setIndentation(classAccess.getLeftCurlyBracketKeyword_3(), classAccess.getRightCurlyBracketKeyword_5()); c.setLinewrap().after(classAccess.getLeftCurlyBracketKeyword_3()); c.setLinewrap(2).after(classAccess.getRightCurlyBracketKeyword_5()); } }